<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('热量表设备数据列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>热量表ID：</label>
                            <input type="text" name="calorimeterId"/>
                        </li>
                        <li>
                            <label>采集器ID：</label>
                            <input type="text" name="concentratorId"/>
                        </li>
                        <li>
                            <label>热量表型号：</label>
                            <select id="calorimeterType" name="typeId">
                                <option value="0">所有</option>
                                <option th:each="calorimeter : ${calorimeterList}" th:text="${calorimeter['typeName']}" th:value="${calorimeter['typeId']}" th:field="*{type.typeId}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>安装时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginInstallTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endInstallTime]"/>
                        </li>
                        <li>
                            <label>安装标识：</label>
                            <select name="status" th:with="type=${@dict.getType('equipment_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="add()" shiro:hasPermission="module:calorimeter:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="module:calorimeter:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="module:calorimeter:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.importExcel()" shiro:hasPermission="module:calorimeter:import">
                <i class="fa fa-download"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="module:calorimeter:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <br/>
            <a class="btn btn-primary multiple disabled" onclick="register()" shiro:hasPermission="module:calorimeter:register">
                <i class="fa fa-download"></i> 热表登记
            </a>
            <a class="btn btn-warning multiple disabled" onclick="cancel()" shiro:hasPermission="module:calorimeter:cancel">
                <i class="fa fa-download"></i> 热表注销
            </a>
            <a class="btn btn-warning multiple disabled" onclick="check()" shiro:hasPermission="module:calorimeter:check">
                <i class="fa fa-download"></i> 读取热表数据
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('module:calorimeter:edit')}]];
    var removeFlag = [[${@permission.hasPermi('module:calorimeter:remove')}]];
    var prefix = ctx + "module/calorimeter/data";
    var datas = [[${@dict.getType('equipment_status')}]];

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            queryParams: queryParams,
            importTemplateUrl: prefix + "/importTemplate",
            modalName: "热量表设备数据",
            columns: [{
                checkbox: true
            },
                {
                    field: 'calorimeterId',
                    title: '热表ID',
                    formatter: function(value, row, index) {
                        return '<a href="javascript:void(0)" onclick="detail(\'' + row.calorimeterId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'status',
                    title: '设备状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'calorimeterType.typeName',
                    title: '热表型号'
                },
                {
                    field: 'concentratorId',
                    title: '采集器'
                },
                {
                    field: 'installTime',
                    title: '安装时间'
                },
                {
                    field: 'installAddress',
                    title: '安装地址'
                },
                {
                    field: 'installUser',
                    title: '安装人'
                },
                {
                    field: 'factory.factoryName',
                    title: '厂商名称'
                },
                {
                    field: 'factory.factoryCode',
                    title: '厂商代码'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.calorimeterId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.calorimeterId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 数据展示 */
        function detail(calorimeterId) {
            var url = ctx + 'module/calorimeter/record/' + calorimeterId;
            $.modal.openTab("热表数据", url);
        }

        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.typeId = $("#calorimeterType").val();
            return search;
        }

        function add(){
            var calorimeterType = $("#calorimeterType option:selected").val();
            $.operate.add(calorimeterType);
        }

        function register(){
            var rows = $.table.selectFirstColumns();
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }

            /*if(rows.length > 10){
                $.modal.alertWarning("一次登记不能超过十条");
                return;
            }*/

            $.modal.confirm("确认要登记选中的热表吗？", function() {
                $.operate.post(prefix + "/register", { "calorimeterIds": rows.join() });
            })
        }

        function cancel(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var status = row["status"];
                if(status=="0"){
                    $.modal.alertWarning("未登记的热表信息不允许注销");
                    return;
                }
            }
            var rows = $.table.selectFirstColumns();
            $.modal.confirm("确认要注销选中的热表吗？", function() {
                $.operate.post(prefix + "/cancel", { "calorimeterIds": rows.join() });
            })
        }

        function check(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var status = row["status"];
                if(status!="1"){
                    $.modal.alertWarning("未登记的热表不能读取热表数据");
                    return;
                }
            }
            var rows = $.table.selectFirstColumns();
            $.modal.confirm("确认要读取选中的热表数据吗？", function() {
                $.operate.post(prefix + "/check", { "calorimeterIds": rows.join() });
            })
        }
</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果热量表信息已经存在，更新这条数据。"> 是否更新已经存在的热量表信息
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>